using EntitiesAndGameState;
using Microsoft.Xna.Framework;

namespace WAG.Logic.SampleLevel
{
    using Game = Microsoft.Xna.Framework.Game;

    public abstract class SoapWavesLayer : GarbageSacLayer
    {
        public SoapWavesLayer(Game game, BaseLevelStats current_score, int num_lives)
            : base(game, current_score, num_lives)
        {
        }

        protected override void UpdateShockWaves(float dt)
        {
            //var slow_motion = CurrentState.slow_motion;
            var current_score = CurrentScore;

            /// Aggiorno le shockwaves
            for (int i = 0; i < CurrentState.shockwaves.Count; i++)
            {
                var sw = CurrentState.shockwaves[i];

                sw.radius += sw.speed * dt;
                if (sw.radius > sw.range)
                {
                    CurrentState.RemoveShockWaveAt(i);
                    i--;
                }
            }
        }

        protected override void ShootShockWave(Vector3 newposition, Faction newfaction, Color newinitialColor, Color newfinalColor, float newrange, float newspeed, float newdamage, Ship shooter,bool audio)
        {
            var sw = new ShockWave(true)// costruttore NON di default: alloca questa reference nel pool
            {
                position = newposition,
                faction = newfaction,
                initialColor = newinitialColor,
                finalColor = newfinalColor,
                range = newrange,
                speed = newspeed,
                damage = newdamage,
                radius = 0.0f,
                shooter = shooter
            };
            CurrentState.shockwaves.Add(sw);
            NewShockWaves.Add(sw);
            //if (newfaction == Faction.None)
            //{
            //    for (int i = 0; i < 10; i++)
            //    {
            //        var dest = Vector3.Zero;
            //        dest.X = MathHelper.Lerp(upperLeft.X, upperRight.X, (float)r.NextDouble());
            //        dest.Z = MathHelper.Lerp(upperLeft.Z, lowerLeft.Z, (float)r.NextDouble());
            //        scene_service.DrawManHoleEngine(newposition, dest, Color.White);
			        
            //    }
            //}
            if(audio)
                audio_service.OnBubbleWave(4);
        }

        protected override void ShootShockWave(Vector3 newposition, Faction newfaction, Color newinitialColor, Color newfinalColor, float newrange, float newspeed, float newdamage, Ship shooter)
        {
            var sw = new ShockWave(true)// costruttore NON di default: alloca questa reference nel pool
            {
                position = newposition,
                faction = newfaction,
                initialColor = newinitialColor,
                finalColor = newfinalColor,
                range = newrange,
                speed = newspeed,
                damage = newdamage,
                radius = 0.0f,
                shooter = shooter
            };
            CurrentState.shockwaves.Add(sw);
            NewShockWaves.Add(sw);
            audio_service.OnBubbleWave(4);
        }

    }
}